var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = require("../../../@babel/runtime/helpers/objectSpread2"), e = require("../../../@babel/runtime/helpers/defineProperty"), o = t(require("../../../dist/dialog/dialog")), s = t(require("../../../utils/util")), i = getApp();

Page({
    data: {
        keyWord: "",
        tabIndex: 0,
        status: 4,
        timer: "",
        tabList: [ {
            status: 4,
            index: 0,
            name: "全部",
            goodsList: [],
            page: 1
        }, {
            status: 0,
            index: 1,
            name: "待付款",
            goodsList: [],
            page: 1
        }, {
            status: 1,
            index: 2,
            name: "待使用",
            goodsList: [],
            page: 1
        }, {
            status: 3,
            index: 3,
            name: "已使用",
            goodsList: [],
            page: 1
        }, {
            status: -1,
            index: 4,
            name: "退款/售后",
            goodsList: [],
            page: 1
        } ],
        orderLastPage: 0,
        isLoadMore: !0,
        storeApiArr: [ "plugin.coupon-store.frontend.order-list.index", "plugin.coupon-store.frontend.order-list.waitPay", "plugin.coupon-store.frontend.order-list.waitSend", "plugin.coupon-store.frontend.order-list.completed", "plugin.coupon-store.frontend.order-list.refund" ]
    },
    onLoad: function(t) {
        var a;
        if ("" !== (null !== (a = t.status) && void 0 !== a ? a : "")) for (var e in this.data.tabList) this.data.tabList[e].status === Number(t.status) && this.setData({
            tabIndex: this.data.tabList[e].index
        });
    },
    storeGoodsList: function() {
        var t = this, a = this.data.storeApiArr[this.data.tabIndex], o = i.getNetAddresss(a), s = {
            page: this.data.tabList[this.data.tabIndex].page,
            keyword: this.data.keyWord
        };
        i._postNetWork({
            url: o,
            data: s,
            success: function(a) {
                var o = a.data;
                if (wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 1 == o.result) {
                    t.data.isLoadMore = !0, t.data.orderLastPage = o.data.last_page, t.data.orderLastPage || (t.data.orderLastPage = 0);
                    var s = t.data.tabIndex;
                    t.data.tabList[s].goodsList;
                    t.setData(e({}, "tabList[" + s + "].goodsList", o.data.data));
                } else t.data.storePage = t.data.storePage - 1, t.data.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.tabList[this.data.tabIndex].page >= this.data.orderLastPage)) {
            this.data.tabList[this.data.tabIndex].page += 1;
            var a = this.data.storeApiArr[this.data.tabIndex];
            console.log(a);
            var o = i.getNetAddresss(a), s = {
                page: this.data.tabList[this.data.tabIndex].page,
                keyword: this.data.keyWord
            };
            i._getNetWork({
                url: o,
                data: s,
                success: function(a) {
                    var o = a.data, s = o.data.data;
                    if (1 == o.result) {
                        t.data.isLoadMore = !0;
                        var i = t.data.tabIndex;
                        t.setData(e({}, "tabList[" + i + "].goodsList", t.data.tabList[i].goodsList.concat(s)));
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onOrderChange: function(t) {
        this.setData({
            tabIndex: t.detail.name
        }), 0 === this.data.tabList[this.data.tabIndex].goodsList.length && this.storeGoodsList();
    },
    orderSearch: function(t) {
        var a = this, e = t.detail;
        console.log(e), this.setData({
            keyWord: e
        }), this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            s.default.debounce(a.storeGoodsList());
        }, 500);
    },
    orderstateOn: function(t) {
        var a = t.currentTarget.dataset, e = a.value, o = a.id, s = a.goodsid, i = a.refundid, n = a.api, d = a.storename;
        this.getorderState({
            value: e,
            id: o,
            goodsId: s,
            refundId: i,
            api: n,
            storename: d
        });
    },
    getorderState: function() {
        var t = this, e = a({}, arguments.length <= 0 ? void 0 : arguments[0]), s = e.value, i = e.id, n = e.goodsId, d = e.refundId, r = e.api, u = e.storename, c = {
            coupon_store_order_detail: "/packageF/consumption/orderDetails/orderDetails?orderId=".concat(i),
            coupon_store_refund_page: "/packageF/consumption/refundOrder/refundOrder?orderId=".concat(i, "&type=2"),
            1: "/packageD/buy/orderPay/orderPay?order_id=".concat(i, "&status=2"),
            41: "".concat(r),
            coupon_store_comment: "/packageF/consumption/evaluate/evaluate?orderId=".concat(i, "&storeName=").concat(u),
            coupon_store_rebuy: "/packageF/consumption/goodsDetails/goodsDetails?goodsId=".concat(n),
            coupon_store_refunding: "/packageF/consumption/refundProcess/refundProcess?refundId=".concat(d),
            coupon_store_refunded: "/packageF/consumption/refundProcess/refundProcess?refundId=".concat(d)
        };
        if ("9" !== s.toString() && "12" !== s.toString()) return wx.navigateTo({
            url: c[s]
        });
        o.default.confirm({
            title: "提示",
            message: 9 === s ? "确定取消该订单?" : "确定删除该订单?"
        }).then(function() {
            9 === s ? t.cancelPay(i, r) : t.deletePay(i, r);
        }).catch(function() {});
    },
    cancelPay: function(t, a) {
        var e = this, o = i.getNetAddresss(a), s = {
            order_id: t
        };
        i._postNetWork({
            url: o,
            data: s,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }), e.storeGoodsList()) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    deletePay: function(t, a) {
        var e = this, o = i.getNetAddresss(a), s = {
            order_id: t
        };
        i._postNetWork({
            url: o,
            data: s,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }), e.storeGoodsList()) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    ondetails: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/consumption/orderDetails/orderDetails?orderId=".concat(a)
        });
    },
    onReady: function() {},
    onShow: function() {
        this.storeGoodsList();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        var t = this.data.tabIndex;
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        }), this.setData(e({}, "tabList[" + t + "].page", 1)), console.log(this.data.tabList[this.data.tabIndex].page), 
        this.storeGoodsList();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {}
});